<?php
if(!extension_loaded('nmdb')) {
    dl('nmdb.' . PHP_SHLIB_SUFFIX);
}

$nmdb = nmdb_init();
echo $nmdb, "\n";
echo nmdb_add_tcp_server($nmdb, "127.0.0.1", -1), "\n";

echo nmdb_set($nmdb, "test1", 'aaa'), "\n";
echo nmdb_set($nmdb, "test2", 'bbb'), "\n";
echo nmdb_set($nmdb, "test3", 'ccc'), "\n";

echo nmdb_get($nmdb, "test1"), "\n";
echo nmdb_get($nmdb, "test2"), "\n";
echo nmdb_get($nmdb, "test3"), "\n";
$s = nmdb_get($nmdb, "test3");
echo strlen($s),"\n";
echo nmdb_del($nmdb, 'test1'), "\n";
echo nmdb_get($nmdb, "test1"), "\n";

echo nmdb_cas($nmdb, "test2", "bbb", "222"), "\n";
$s = nmdb_get($nmdb, "test2");
echo $s,"\t",strlen($s),"\n";

echo nmdb_cas($nmdb, "test2", "2", "bbbb"), "\n";
echo nmdb_get($nmdb, "test2"), "\n";
echo nmdb_incr($nmdb, "test2", 1), "\n";
$v = nmdb_get($nmdb, "test2");
echo strlen($v)."[$v]\n";
echo trim($v),"\n";
for ($i = 0; $i < strlen($v); $i++) {
  echo dechex(ord($v[$i])),",";
}
echo "\n";

echo nmdb_incr($nmdb, "test2", 2), "\n";
$v = nmdb_get($nmdb, "test2");
echo strlen($v)."[$v]\n";

echo nmdb_incr($nmdb, "test2", 4), "\n";
$v = nmdb_get($nmdb, "test2");
echo strlen($v)."[$v]\n";

nmdb_free($nmdb);


